<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>范例</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.solr-get-version.html">solr_get_version</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.solrutils.html">SolrUtils</a></div>
 <div class="up"><a href="book.solr.html">Solr</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="solr.examples" class="chapter">
 <h1>范例</h1>

 
    <p class="para">
        Examples of how to use the Apache Solr extension in PHP
    </p>
    <div class="example" id="example-4609">
        <p><strong>Example #1 Contents of the BootStrap file</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Domain&nbsp;name&nbsp;of&nbsp;the&nbsp;Solr&nbsp;server&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SERVER_HOSTNAME'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'solr.example.com'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Whether&nbsp;or&nbsp;not&nbsp;to&nbsp;run&nbsp;in&nbsp;secure&nbsp;mode&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SECURE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;HTTP&nbsp;Port&nbsp;to&nbsp;connection&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SERVER_PORT'</span><span style="color: #007700">,&nbsp;((</span><span style="color: #0000BB">SOLR_SECURE</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #0000BB">8443&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">8983</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;HTTP&nbsp;Basic&nbsp;Authentication&nbsp;Username&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SERVER_USERNAME'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'admin'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;HTTP&nbsp;Basic&nbsp;Authentication&nbsp;password&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SERVER_PASSWORD'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'changeit'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;HTTP&nbsp;connection&nbsp;timeout&nbsp;*/<br />/*&nbsp;This&nbsp;is&nbsp;maximum&nbsp;time&nbsp;in&nbsp;seconds&nbsp;allowed&nbsp;for&nbsp;the&nbsp;http&nbsp;data&nbsp;transfer&nbsp;operation.&nbsp;Default&nbsp;value&nbsp;is&nbsp;30&nbsp;seconds&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SERVER_TIMEOUT'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;File&nbsp;name&nbsp;to&nbsp;a&nbsp;PEM-formatted&nbsp;private&nbsp;key&nbsp;+&nbsp;private&nbsp;certificate&nbsp;(concatenated&nbsp;in&nbsp;that&nbsp;order)&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SSL_CERT'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'certs/combo.pem'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;File&nbsp;name&nbsp;to&nbsp;a&nbsp;PEM-formatted&nbsp;private&nbsp;certificate&nbsp;only&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SSL_CERT_ONLY'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'certs/solr.crt'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;File&nbsp;name&nbsp;to&nbsp;a&nbsp;PEM-formatted&nbsp;private&nbsp;key&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SSL_KEY'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'certs/solr.key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Password&nbsp;for&nbsp;PEM-formatted&nbsp;private&nbsp;key&nbsp;file&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SSL_KEYPASSWORD'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'StrongAndSecurePassword'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Name&nbsp;of&nbsp;file&nbsp;holding&nbsp;one&nbsp;or&nbsp;more&nbsp;CA&nbsp;certificates&nbsp;to&nbsp;verify&nbsp;peer&nbsp;with*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SSL_CAINFO'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'certs/cacert.crt'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Name&nbsp;of&nbsp;directory&nbsp;holding&nbsp;multiple&nbsp;CA&nbsp;certificates&nbsp;to&nbsp;verify&nbsp;peer&nbsp;with&nbsp;*/<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'SOLR_SSL_CAPATH'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'certs/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>


    </div>

 <div class="example" id="example-4610">
  <p><strong>Example #2 Adding a document to the index</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrInputDocument</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">334455</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Software'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Lucene'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addDocument</span><span style="color: #007700">(</span><span style="color: #0000BB">$doc</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 446
        )

)
</pre></div>
  </div>
 </div>
 
 <div class="example" id="example-4611">
  <p><strong>Example #3 Merging one document into another document</strong></p>
  <div class="example-contents">
   <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrDocument</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$second_doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrDocument</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1123</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">features&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"PHP&nbsp;Client&nbsp;Side"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">features&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Fast&nbsp;development&nbsp;cycles"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">[</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">'Software'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">[</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">'Custom&nbsp;Search'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">cat&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Information&nbsp;Technology'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$second_doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Lucene&nbsp;Search'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$second_doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">merge</span><span style="color: #007700">(</span><span style="color: #0000BB">$doc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$second_doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">toArray</span><span style="color: #007700">());<br /><br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
   <div class="cdata"><pre>
Array
(
    [document_boost] =&gt; 0
    [field_count] =&gt; 3
    [fields] =&gt; Array
        (
            [0] =&gt; SolrDocumentField Object
                (
                    [name] =&gt; cat
                    [boost] =&gt; 0
                    [values] =&gt; Array
                        (
                            [0] =&gt; Software
                            [1] =&gt; Custom Search
                            [2] =&gt; Information Technology
                        )

                )

            [1] =&gt; SolrDocumentField Object
                (
                    [name] =&gt; id
                    [boost] =&gt; 0
                    [values] =&gt; Array
                        (
                            [0] =&gt; 1123
                        )

                )

            [2] =&gt; SolrDocumentField Object
                (
                    [name] =&gt; features
                    [boost] =&gt; 0
                    [values] =&gt; Array
                        (
                            [0] =&gt; PHP Client Side
                            [1] =&gt; Fast development cycles
                        )

                )

        )

)
</pre></div>
  </div>
 </div>
 
 
 <div class="example" id="example-4612">
  <p><strong>Example #4 Searching for documents - SolrObject responses</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'lucene'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStart</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRows</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'features'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'timestamp'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query_response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$query_response</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$response</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 1
            [params] =&gt; SolrObject Object
                (
                    [wt] =&gt; xml
                    [rows] =&gt; 50
                    [start] =&gt; 0
                    [indent] =&gt; on
                    [q] =&gt; lucene
                    [fl] =&gt; cat,features,id,timestamp
                    [version] =&gt; 2.2
                )

        )

    [response] =&gt; SolrObject Object
        (
            [numFound] =&gt; 3
            [start] =&gt; 0
            [docs] =&gt; Array
                (
                    [0] =&gt; SolrObject Object
                        (
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; Software
                                    [1] =&gt; Lucene
                                )

                            [id] =&gt; 334456
                        )

                    [1] =&gt; SolrObject Object
                        (
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; Software
                                    [1] =&gt; Lucene
                                )

                            [id] =&gt; 334455
                        )

                    [2] =&gt; SolrObject Object
                        (
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; software
                                    [1] =&gt; search
                                )

                            [features] =&gt; Array
                                (
                                    [0] =&gt; Advanced Full-Text Search Capabilities using Lucene
                                    [1] =&gt; Optimized for High Volume Web Traffic
                                    [2] =&gt; Standards Based Open Interfaces - XML and HTTP
                                    [3] =&gt; Comprehensive HTML Administration Interfaces
                                    [4] =&gt; Scalability - Efficient Replication to other Solr Search Servers
                                    [5] =&gt; Flexible and Adaptable with XML configuration and Schema
                                    [6] =&gt; Good unicode support: héllo (hello with an accent over the e)
                                )

                            [id] =&gt; SOLR1000
                            [timestamp] =&gt; 2009-09-04T20:38:55.906
                        )

                )

        )

)
</pre></div>
  </div>
 </div>
 
 <div class="example" id="example-4613">
  <p><strong>Example #5 Searching for documents - SolrDocument responses</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'lucene'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStart</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRows</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'features'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'timestamp'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query_response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query_response</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setParseMode</span><span style="color: #007700">(</span><span style="color: #0000BB">SolrQueryResponse</span><span style="color: #007700">::</span><span style="color: #0000BB">PARSE_SOLR_DOC</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$query_response</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$response</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
   <div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 1
            [params] =&gt; SolrObject Object
                (
                    [wt] =&gt; xml
                    [rows] =&gt; 50
                    [start] =&gt; 0
                    [indent] =&gt; on
                    [q] =&gt; lucene
                    [fl] =&gt; cat,features,id,timestamp
                    [version] =&gt; 2.2
                )

        )

    [response] =&gt; SolrObject Object
        (
            [numFound] =&gt; 3
            [start] =&gt; 0
            [docs] =&gt; Array
                (
                    [0] =&gt; SolrDocument Object
                        (
                            [_hashtable_index:SolrDocument:private] =&gt; 19740
                        )

                    [1] =&gt; SolrDocument Object
                        (
                            [_hashtable_index:SolrDocument:private] =&gt; 25485
                        )

                    [2] =&gt; SolrDocument Object
                        (
                            [_hashtable_index:SolrDocument:private] =&gt; 25052
                        )

                )

        )

)
</pre></div>
  </div>
 </div>
    
 <div class="example" id="example-4614">
        <p><strong>Example #6 Simple TermsComponent example - basic</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerms</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTermsField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>以上例程的输出类似于：</p></div>
        <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 2
        )

    [terms] =&gt; SolrObject Object
        (
            [cat] =&gt; SolrObject Object
                (
                    [electronics] =&gt; 14
                    [Lucene] =&gt; 4
                    [Software] =&gt; 4
                    [memory] =&gt; 3
                    [card] =&gt; 2
                    [connector] =&gt; 2
                    [drive] =&gt; 2
                    [graphics] =&gt; 2
                    [hard] =&gt; 2
                    [monitor] =&gt; 2
                )

        )

)

</pre></div>
        </div>
 </div>
    
<div class="example" id="example-4615">
    <p><strong>Example #7 Simple TermsComponent example - using a prefix</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerms</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Return&nbsp;only&nbsp;terms&nbsp;starting&nbsp;with&nbsp;$prefix&nbsp;*/<br /></span><span style="color: #0000BB">$prefix&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'c'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTermsField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setTermsPrefix</span><span style="color: #007700">(</span><span style="color: #0000BB">$prefix</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 1
        )

    [terms] =&gt; SolrObject Object
        (
            [cat] =&gt; SolrObject Object
                (
                    [card] =&gt; 2
                    [connector] =&gt; 2
                    [camera] =&gt; 1
                    [copier] =&gt; 1
                )

        )

)
</pre></div>
    </div>
</div>
    
<div class="example" id="example-4616">
    <p><strong>Example #8 Simple TermsComponent example - specifying a minimum frequency</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerms</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Return&nbsp;only&nbsp;terms&nbsp;starting&nbsp;with&nbsp;$prefix&nbsp;*/<br /></span><span style="color: #0000BB">$prefix&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'c'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Return&nbsp;only&nbsp;terms&nbsp;with&nbsp;a&nbsp;frequency&nbsp;of&nbsp;2&nbsp;or&nbsp;greater&nbsp;*/<br /></span><span style="color: #0000BB">$min_frequency&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTermsField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setTermsPrefix</span><span style="color: #007700">(</span><span style="color: #0000BB">$prefix</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setTermsMinCount</span><span style="color: #007700">(</span><span style="color: #0000BB">$min_frequency</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 0
        )

    [terms] =&gt; SolrObject Object
        (
            [cat] =&gt; SolrObject Object
                (
                    [card] =&gt; 2
                    [connector] =&gt; 2
                )

        )

)
</pre></div>
    </div>
</div>
    
<div class="example" id="example-4617">
<p><strong>Example #9 Simple Facet Example</strong></p>
<div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'*:*'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFacet</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFacetField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addFacetField</span><span style="color: #007700">(</span><span style="color: #DD0000">'name'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setFacetMinCount</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response_array&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$facet_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$response_array</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">facet_counts</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">facet_fields</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$facet_data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
</div>

<div class="example-contents"><p>以上例程的输出类似于：</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [cat] =&gt; SolrObject Object
        (
            [electronics] =&gt; 14
            [memory] =&gt; 3
            [Lucene] =&gt; 2
            [Software] =&gt; 2
            [card] =&gt; 2
            [connector] =&gt; 2
            [drive] =&gt; 2
            [graphics] =&gt; 2
            [hard] =&gt; 2
            [monitor] =&gt; 2
            [search] =&gt; 2
            [software] =&gt; 2
        )

    [name] =&gt; SolrObject Object
        (
            [gb] =&gt; 6
            [1] =&gt; 3
            [184] =&gt; 3
            [2] =&gt; 3
            [3200] =&gt; 3
            [400] =&gt; 3
            [500] =&gt; 3
            [ddr] =&gt; 3
            [i] =&gt; 3
            [ipod] =&gt; 3
            [memori] =&gt; 3
            [pc] =&gt; 3
            [pin] =&gt; 3
            [pod] =&gt; 3
            [sdram] =&gt; 3
            [system] =&gt; 3
            [unbuff] =&gt; 3
            [canon] =&gt; 2
            [corsair] =&gt; 2
            [drive] =&gt; 2
            [hard] =&gt; 2
            [mb] =&gt; 2
            [n] =&gt; 2
            [power] =&gt; 2
            [retail] =&gt; 2
            [video] =&gt; 2
            [x] =&gt; 2
        )

)
</pre></div>
</div>
</div>
    
<div class="example" id="example-4618">
    <p><strong>Example #10 Simple Facet Example - with optional field override for mincount</strong></p>
    <div class="example-contents">
        <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'*:*'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFacet</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFacetField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addFacetField</span><span style="color: #007700">(</span><span style="color: #DD0000">'name'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setFacetMinCount</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setFacetMinCount</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'name'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response_array&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$facet_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$response_array</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">facet_counts</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">facet_fields</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$facet_data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
        <div class="cdata"><pre>
SolrObject Object
(
    [cat] =&gt; SolrObject Object
        (
            [electronics] =&gt; 14
            [memory] =&gt; 3
            [Lucene] =&gt; 2
            [Software] =&gt; 2
            [card] =&gt; 2
            [connector] =&gt; 2
            [drive] =&gt; 2
            [graphics] =&gt; 2
            [hard] =&gt; 2
            [monitor] =&gt; 2
            [search] =&gt; 2
            [software] =&gt; 2
        )

    [name] =&gt; SolrObject Object
        (
            [gb] =&gt; 6
        )

)
</pre></div>
    </div>
</div>

<div class="example" id="example-4619">
        <p><strong>Example #11 Connecting to SSL-Enabled Server</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'timeout'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_TIMEOUT</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'secure'&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SECURE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'ssl_cert'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SSL_CERT_ONLY</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'ssl_key'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SSL_KEY</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'ssl_keypassword'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SSL_KEYPASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'ssl_cainfo'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SSL_CAINFO</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'*:*'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFacet</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFacetField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addFacetField</span><span style="color: #007700">(</span><span style="color: #DD0000">'name'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setFacetMinCount</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">setFacetMinCount</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'name'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response_array&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$facet_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$response_array</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">facet_counts</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">facet_fields</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$facet_data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>以上例程的输出类似于：</p></div>
        <div class="example-contents screen">
            <div class="cdata"><pre>
SolrObject Object
(
    [cat] =&gt; SolrObject Object
        (
            [electronics] =&gt; 14
            [memory] =&gt; 3
            [Lucene] =&gt; 2
            [Software] =&gt; 2
            [card] =&gt; 2
            [connector] =&gt; 2
            [drive] =&gt; 2
            [graphics] =&gt; 2
            [hard] =&gt; 2
            [monitor] =&gt; 2
            [search] =&gt; 2
            [software] =&gt; 2
        )

    [name] =&gt; SolrObject Object
        (
            [gb] =&gt; 6
        )

)
</pre></div>
        </div>
    </div>
    
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.solr-get-version.html">solr_get_version</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.solrutils.html">SolrUtils</a></div>
 <div class="up"><a href="book.solr.html">Solr</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
